@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">{{ isset($lottery) ? '编辑摇奖活动' : '创建摇奖活动' }}</div>

                <div class="card-body">
                    <form method="POST" action="{{ isset($lottery) ? route('admin.lottery.update', $lottery->id) : route('admin.lottery.store') }}">
                        @csrf
                        @if(isset($lottery))
                            @method('PUT')
                        @endif

                        <div class="mb-3">
                            <label for="name" class="form-label">活动名称</label>
                            <input type="text" 
                                   class="form-control @error('name') is-invalid @enderror" 
                                   id="name" 
                                   name="name" 
                                   value="{{ old('name', $lottery->name ?? '') }}" 
                                   required>
                            @error('name')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>

                        <div class="mb-3">
                            <label for="start_time" class="form-label">开始时间</label>
                            <input type="datetime-local" 
                                   class="form-control @error('start_time') is-invalid @enderror" 
                                   id="start_time" 
                                   name="start_time" 
                                   value="{{ old('start_time', isset($lottery) ? date('Y-m-d\TH:i', strtotime($lottery->start_time)) : '') }}" 
                                   required>
                            @error('start_time')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>

                        <div class="mb-3">
                            <label for="end_time" class="form-label">结束时间</label>
                            <input type="datetime-local" 
                                   class="form-control @error('end_time') is-invalid @enderror" 
                                   id="end_time" 
                                   name="end_time" 
                                   value="{{ old('end_time', isset($lottery) ? date('Y-m-d\TH:i', strtotime($lottery->end_time)) : '') }}" 
                                   required>
                            @error('end_time')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>

                        <div class="mb-3">
                            <label for="description" class="form-label">活动描述</label>
                            <textarea class="form-control @error('description') is-invalid @enderror" 
                                      id="description" 
                                      name="description" 
                                      rows="3">{{ old('description', $lottery->description ?? '') }}</textarea>
                            @error('description')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>

                        <div class="mb-3">
                            <label for="status" class="form-label">状态</label>
                            <select class="form-select @error('status') is-invalid @enderror" 
                                    id="status" 
                                    name="status">
                                <option value="0" {{ (old('status', $lottery->status ?? '') == 0) ? 'selected' : '' }}>未开始</option>
                                <option value="1" {{ (old('status', $lottery->status ?? '') == 1) ? 'selected' : '' }}>进行中</option>
                                <option value="2" {{ (old('status', $lottery->status ?? '') == 2) ? 'selected' : '' }}>已结束</option>
                            </select>
                            @error('status')
                                <div class="invalid-feedback">{{ $message }}</div>
                            @enderror
                        </div>

                        <div class="d-flex justify-content-between">
                            <a href="{{ route('admin.lottery.index') }}" class="btn btn-secondary">返回</a>
                            <button type="submit" class="btn btn-primary">
                                {{ isset($lottery) ? '更新' : '创建' }}
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection 